﻿using System.ComponentModel;
using System.Web.Mvc;
using ShopB2C.Entity;
using ShopB2C.Enums;
using ShopB2C.ViewModels;
using Valor.Helper;

namespace xTeam.HengLe.Controller.Manage
{
    public partial class MemberController : BaseController
    {

        /// <summary>
        /// 
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        public ActionResult MemberProfile(int uid = 0)
        {
            this.SiteMapPathAdd("用户列表");

            UserEntity userProfile = _userAccess.UserProfile(uid);
            ViewData["LevelId"] = new SelectList(_rolesAccess.GetRoles() , "LevelId" , "Name" , userProfile.LevelId);
            ViewData["Enabled"] = new SelectList(EnumHelper.GetEnumsToList(typeof(UserState)) , "Value" , "Text" , userProfile.Enabled);

            ViewData["UserFaceRoot"] = _userFaceRoot;
            this.SiteMapPathAdd(string.Format("{0} -- 用户信息查看" , userProfile.NickName));
            return View(userProfile);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="enabled"></param>
        /// <param name="levelId"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult MemberProfile(int uid = 0 , int enabled = 0 , int levelId = 0)
        {
            _userAccess.UpdateUserState(uid , (int)((UserState)enabled) , levelId);
            return RedirectToAction("MemberProfile" , new { uid = uid });
        }
        /// <summary>
        /// 用户列表
        /// </summary>
        /// <returns></returns>
        public ActionResult UserList([DefaultValue(1)]int number)
        {
            this.SiteMapPathAdd("用户列表");
            int pageCount = 0;
            UserViewModel viewModel = new UserViewModel();

            viewModel.UserList = _userAccess.UserList(40 , number , ref pageCount);
            viewModel.RolesList = _rolesAccess.GetRoles();
            ViewData["Pager"] = this.CreatePager("{0}" , pageCount , number);
            return View(viewModel);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="uid">用户编号</param>
        public ActionResult DeleteUser([DefaultValue(0)]int uid)
        {
            return new EmptyResult();
        }


    }
}
